import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
import { ApiProperty } from '@nestjs/swagger';

export type TaskDocument = Task & Document;

@Schema({ timestamps: true })
export class Task {
  @ApiProperty({ description: '任务名称', example: '清理日志' })
  @Prop({ required: true })
  name: string;

  @ApiProperty({ description: 'Cron表达式', example: '0 0 * * *' })
  @Prop({ required: true })
  cronExpression: string;

  @ApiProperty({ description: '是否激活', default: true })
  @Prop({ default: true })
  isActive: boolean;

  @ApiProperty({ description: '任务描述' })
  @Prop()
  description: string;

  @ApiProperty({ description: '最后执行时间' })
  @Prop()
  lastRunTime: Date;

  @ApiProperty({ description: '下次执行时间' })
  @Prop()
  nextRunTime: Date;
}

export const TaskSchema = SchemaFactory.createForClass(Task); 